Shell Scripting
Shell Scripting – The Geek Diary #shell
特殊文字
$@ コマンドの引数。全部入る
どうやって分割する? $1, $2, ,,,としていく arrayにしたい場合は、 https://wiki.bash-hackers.org/syntax/arrays
Special Characters and Quoting - Learning the bash Shell, Second Edition
home directory, substitution, variable expression, background job, start subshell, quote, pipe, star character-set
以下は、シェルスクリプト レシピより
loop
code:loop.sh
#!/bin/sh
i=10
while $i -le 30 ; do
echo $i
i=expr $i + 1
done
入力
code: read.sh
!/bin/sh
msg=""
while -z "$msg" ; do
echo "入力してください"
read msg
echo "入力は${msg}"
done
ミス対策
set -u
ブロック {} 内にscopeを限定するために、local foo と宣言する
変数に値を入れた後に、readonly にする
変数
null値にするには foo="" 未定義にするには unset foo
環境変数
IFS 区切り文字
#linux_command